package com.game.db;

import com.dats.db.NameMap;
import com.game.bean.BaseRole;

import java.util.HashMap;
import java.util.Map;

/**
 * @author sig
 * @since 2016/9/25
 */
public enum BaseNameKey {
    baseRole(BaseRole.class, "baseRole"),
    ;

    private String tableName;
    private Class<?> clazz;
    private static Map<Class<?>, String> classMap = new HashMap<>();

    static {
        for (BaseNameKey nameKey : BaseNameKey.values())
            classMap.put(nameKey.getClazz(), nameKey.getTableName());
    }

    BaseNameKey(Class<?> clazz, String tableName) {
        this.clazz = clazz;
        this.tableName = tableName.toLowerCase();
    }

    public Class<?> getClazz() {
        return clazz;
    }

    public String getTableName() {
        return tableName;
    }

    public static Map<Class<?>, String> getClassMap() {
        return classMap;
    }

    public static void put(Class<?> clazz) {
        String tableName = classMap.get(clazz);

        if (null != tableName)
            NameMap.put(clazz, tableName);
    }

    public static void putAll() {
        for (Class<?> clazz : classMap.keySet()) {

            if (null == clazz) continue;
            put(clazz);
        }
    }
}
